<template>
  <div>
    <!--  -->
  </div>
</template>
<script>
export default {
  components: {},
  data() {
    return {}
  },
  created() {
    console.log(this.findValue(2))
  },
  methods: {
    // forEach push pop unshift shift map  filter reduce  every  some  find  findIndex  indexOf  includes

    findValue(id) {
      const arr = [
        {
          id: 1,
          value: '正式'
        },
        {
          id: 2,
          value: '非正式'
        }
      ]
      // findIndex:找出符合条件项的下标，找不到返回-1
      // const _findIndex = arr.findIndex((item) => item.id === id)
      // return _findIndex === -1 ? '-' : arr[_findIndex].value
      // filter:返回符合条件的项组成的数组
      // const arr2 = arr.filter((item) => item.id === id)
      // return arr2.length === 1 ? arr2[0].value : '-'
      // forEach:循环
      let val = '-'
      arr.forEach((item) => {
        if (item.id === id) {
          val = item.value
        }
      })
      return val
    }
  }
}
</script>
<style></style>
>
